const Chunk = require("../template")

function testChunkPerformance() {
  console.log(
    "1. 大量数据分块性能测试:",
    (() => {
      const arr = Array.from({ length: 10000 }, (_, i) => i + 1)
      const start = performance.now()
      Chunk.chunk(arr, 100)
      const end = performance.now()
      return (end - start) < 100 // 100ms内完成
    })()
  )

  console.log(
    "2. 大量数据按数量分块性能测试:",
    (() => {
      const arr = Array.from({ length: 10000 }, (_, i) => i + 1)
      const start = performance.now()
      Chunk.chunkByCount(arr, 100)
      const end = performance.now()
      return (end - start) < 100 // 100ms内完成
    })()
  )

  console.log(
    "3. 大量数据不可变分块性能测试:",
    (() => {
      const arr = Array.from({ length: 1000 }, (_, i) => i + 1)
      const start = performance.now()
      Chunk.chunkImmutable(arr, 100)
      const end = performance.now()
      return (end - start) < 100 // 100ms内完成
    })()
  )

  console.log(
    "4. 大量数据带步长分块性能测试:",
    (() => {
      const arr = Array.from({ length: 1000 }, (_, i) => i + 1)
      const start = performance.now()
      Chunk.chunkWithStep(arr, 100, 50)
      const end = performance.now()
      return (end - start) < 100 // 100ms内完成
    })()
  )

  console.log(
    "5. 大量数据带填充分块性能测试:",
    (() => {
      const arr = Array.from({ length: 1000 }, (_, i) => i + 1)
      const start = performance.now()
      Chunk.chunkWithFill(arr, 100, 0)
      const end = performance.now()
      return (end - start) < 100 // 100ms内完成
    })()
  )

  console.log(
    "6. 大量数据带过滤分块性能测试:",
    (() => {
      const arr = Array.from({ length: 1000 }, (_, i) => i + 1)
      const start = performance.now()
      Chunk.chunkWithFilter(arr, 100, (item) => item % 2 === 0)
      const end = performance.now()
      return (end - start) < 100 // 100ms内完成
    })()
  )

  console.log(
    "7. 大量数据带映射分块性能测试:",
    (() => {
      const arr = Array.from({ length: 1000 }, (_, i) => i + 1)
      const start = performance.now()
      Chunk.chunkWithMap(arr, 100, (item) => item * 2)
      const end = performance.now()
      return (end - start) < 100 // 100ms内完成
    })()
  )

  console.log(
    "8. 大量数据带进度回调分块性能测试:",
    (() => {
      const arr = Array.from({ length: 1000 }, (_, i) => i + 1)
      const start = performance.now()
      Chunk.chunkWithProgress(arr, 100, (item) => item * 2, () => {})
      const end = performance.now()
      return (end - start) < 100 // 100ms内完成
    })()
  )

  console.log(
    "9. 大量数据带错误处理分块性能测试:",
    (() => {
      const arr = Array.from({ length: 1000 }, (_, i) => i + 1)
      const start = performance.now()
      Chunk.chunkWithErrorHandling(arr, 100, (item) => item * 2, () => [])
      const end = performance.now()
      return (end - start) < 100 // 100ms内完成
    })()
  )

  console.log(
    "10. 大量数据带取消分块性能测试:",
    (() => {
      const arr = Array.from({ length: 1000 }, (_, i) => i + 1)
      const start = performance.now()
      Chunk.chunkWithCancel(arr, 100, (item) => item * 2, { cancelled: false })
      const end = performance.now()
      return (end - start) < 100 // 100ms内完成
    })()
  )

  console.log(
    "11. this上下文性能测试:",
    (() => {
      const perfObj = {
        multiplier: 2,
        processPerformance: function(arr) {
          const start = performance.now()
          const chunks = Chunk.chunk(arr, 100)
          const end = performance.now()
          const time = end - start
          
          return {
            time: time,
            result: chunks.length * this.multiplier
          }
        }
      }
      
      const arr = Array.from({ length: 1000 }, (_, i) => i + 1)
      const result = perfObj.processPerformance(arr)
      
      return result.time < 100 && result.result > 0
    })()
  )

  console.log(
    "12. 分块性能一致性测试:",
    (() => {
      const arr = Array.from({ length: 1000 }, (_, i) => i + 1)
      
      // 测试不同分块方法的一致性
      const methods = [
        () => Chunk.chunk(arr, 100),
        () => Chunk.chunkByCount(arr, 10),
        () => Chunk.chunkImmutable(arr, 100),
        () => Chunk.chunkWithStep(arr, 100, 100),
        () => Chunk.chunkWithFill(arr, 100, 0)
      ]
      
      const results = methods.map(method => {
        const start = performance.now()
        const result = method()
        const end = performance.now()
        return {
          time: end - start,
          length: result.length
        }
      })
      
      return results.every(result => result.time < 100 && result.length > 0)
    })()
  )
}

testChunkPerformance()
